package sqlgenerator

import (
	"fmt"

	"gitee.com/knowgo/gpa/engine/constants"
)

var (
	generators = map[constants.DIALECT]SQLGenerator{}
	reserveds  = map[constants.DIALECT]Reserved{}
)

func register(dialect constants.DIALECT, gen SQLGenerator, reserved Reserved) {
	generators[dialect] = gen
	reserveds[dialect] = reserved
}

func GetGenerator(dialect constants.DIALECT) (SQLGenerator, error) {
	gen := generators[dialect]
	if gen == nil {
		return nil, fmt.Errorf("unsupported dialect type: %v", dialect)
	}
	return gen, nil
}

func GetReserved(dialect constants.DIALECT) (Reserved, error) {
	fn := reserveds[dialect]
	if fn == nil {
		return nil, fmt.Errorf("unsupported dialect type: %v", dialect)
	}
	return fn, nil
}
